<!doctype html>
<html>
<head>
<meta http-equiv=content-type content="text/html; charset=UTF-8"/>
<link rel="shortcut icon" href=mahjong.ico type="image/x-icon"/>
<meta name="keywords" content="天津麻将, 麻将, 天津, HTML, JavaScript, HTML5" />
<meta name="description" content="单机的天津麻将网页应用游戏，支持各浏览器的最新版本。使用GNU GPL v3发布。田生" />
<meta rel="canonical" href="http://59.78.23.223:8080/tjmj/" />
<title>天津麻将</title>
<style>body, input, button, #main_body{font-size:18px;font-family:Microsoft YaHei, 微软雅黑, Heiti SC, 黑体, helvetica neue, lucida grande, helvetica, arial;border:0 none;margin:0;padding:0;background:transparent;color:#FFF;}
body{background:#8C8;overflow:hidden;}
*{-moz-user-select:none;-webkit-user-select:none;}
#main_body{width:800px;height:600px;background:#596;margin:auto;border:#000;}
header{display:block;position:static;width:100%;float:none;margin:0px;height:18px;padding:16px 0;}
header>div{position:relative;float:left;}
#gz{margin:0 0 0 40px;}
#gzsd{cursor:pointer;}
#sy_d{margin:0 0 0 160px;}
#sy{width:1.5em;text-align:center;}
#qszf_d{margin:0 0 0 20px;}
#qs{width:0.75em;}
#zf{width:1em;}
#hxs{margin:0 0 0 140px;}
#hxsm{position:relative;float:right;margin:-26px 0;}
#xp, #sp, #fs, #xz, #dc, #hup{display:block;position:static;float:none;width:800px;height:550px;top:50px;margin:0 0 -550px 0;}
#act{display:block;margin:0 0 -10px;padding:0;height:10px;width:800px;font-size:9px;color:#596;} #act:hover{color:#AFB;}
#act.h2~#xp>#huangp, #act.h2~#xp>#pc{display:none;}
#act:not(.h2)~#hup{display:none;}
#act:not(.h1)~#xp>#huangp{display:none;}
#act.h1~#xp>#pc>#dcm{display:none;}
.w1, .w2, .w3, .w4, .w5, .w6, .w7, .w8, .w9,
.b1, .b2, .b3, .b4, .b5, .b6, .b7, .b8, .b9,
.t1, .t2, .t3, .t4, .t5, .t6, .t7, .t8, .t9,
.z1, .z2, .z3, .z4, .z5, .z6, .z7, .z8, .z9,
.z0{display:inline-block;height:60px;width:42px;margin:0 -6px 0 0;float:none;position:static;background-repeat:no-repeat;background-origin:content-box;background-position:0 10px;}
.w1{background-image:url("");}
.w2{background-image:url("");}
.w3{background-image:url("");}
.w4{background-image:url("");}
.w5{background-image:url("");}
.w6{background-image:url("");}
.w7{background-image:url("");}
.w8{background-image:url("");}
.w9{background-image:url("");}
.b1{background-image:url("");}
.b2{background-image:url("");}
.b3{background-image:url("");}
.b4{background-image:url("");}
.b5{background-image:url("");}
.b6{background-image:url("");}
.b7{background-image:url("");}
.b8{background-image:url("");}
.b9{background-image:url("");}
.t1{background-image:url("");}
.t2{background-image:url("");}
.t3{background-image:url("");}
.t4{background-image:url("");}
.t5{background-image:url("");}
.t6{background-image:url("");}
.t7{background-image:url("");}
.t8{background-image:url("");}
.t9{background-image:url("");}
.z0{background-image:url("");}
.z1{background-image:url("");}
.z2{background-image:url("");}
.z3{background-image:url("");}
.z4{background-image:url("");}
.z5{background-image:url("");}
.z6{background-image:url("");}
.z7{background-image:url("");}
#su:not(.xs)>:not(#su4):not(.xs).p0>div:not(.z9),
#su:not(.xs)>:not(#su4):not(.xs).p1>div:not(.z9):nth-last-child(n+4),
#su:not(.xs)>:not(#su4):not(.xs).p2>div:not(.z9):nth-last-child(n+7),
#su:not(.xs)>:not(#su4):not(.xs).p3>div:not(.z9):nth-last-child(n+10),
#su:not(.xs)>:not(#su4):not(.xs).p4>div:not(.z9):nth-last-child(n+13),
.z8{background-image:url("");}
.z9{background-image:url("");}
#hxsp{display:none;}
#su1, #su2, #su3, #su4{border:0 none;display:block;position:relative;width:530px;height:60px;padding:0;margin:0 0 -60px;}
#su1{-moz-transform:rotate(90deg);-o-transform:rotate(90deg);-webkit-transform:rotate(90deg);-ms-transform:rotate(90deg);transform:rotate(90deg);top:240px;left:-215px;}
#su2{-moz-transform:rotate(180deg);-o-transform:rotate(180deg);-webkit-transform:rotate(180deg);-ms-transform:rotate(180deg);transform:rotate(180deg);top:20px;left:135px;}
#su3{-moz-transform:rotate(270deg);-o-transform:rotate(270deg);-webkit-transform:rotate(270deg);-ms-transform:rotate(270deg);-transform-transform:rotate(270deg);top:240px;left:485px;}
#su4{top:460px;left:135px;}
#su>.p0>:nth-child(14),
#su>.p1>:nth-child(11),
#su>.p2>:nth-child(8),
#su>.p3>:nth-child(5),
#su>.p4>:nth-child(2){margin-left:16px;}
#su>.p1>:nth-child(n+12),
#su>.p2>:nth-child(n+9),
#su>.p3>:nth-child(n+6),
#su>.p4>:nth-child(n+3){margin-left:-8px;}
#su>.p1>:nth-child(3n+12),
#su>.p2>:nth-child(3n+9),
#su>.p3>:nth-child(3n+6),
#su>.p4>:nth-child(3n+3){margin-left:16px !important;}
#act.p4:not(.mv)~#su>#su4.p0>div:hover,
#act.p4:not(.mv)~#su>#su4.p1>div:nth-last-child(n+4):hover,
#act.p4:not(.mv)~#su>#su4.p2>div:nth-last-child(n+7):hover,
#act.p4:not(.mv)~#su>#su4.p3>div:nth-last-child(n+10):hover,
#act.p4:not(.mv)~#su>#su4.p4>div:nth-last-child(n+13):hover{background-position:0 0;cursor:pointer;}
#act.p4~#xp>#xz{display:block;}
#act.apg~#xp>#xz{display:block;}
div.g2{display:inline;}
div.g2>div:first-child{margin-left:-11px;}
div.g2>div:nth-child(2){margin-left:-19px;}
div.g2+div{margin-left:-19px !important;}#pc{display:block;position:static;float:none;width:800px;height:960px;top:50px;margin:550px 0 -1510px 0;}
#pc1, #pc2, #pc3, #pc4{border:0 none;padding:0;display:block;position:relative;width:300px;height:240px;padding:0;margin:0;padding:15px 5px;}
#pc1>div, #pc2>div, #pc3>div, #pc4>div{-moz-transform:rotate(180deg);-o-transform:rotate(180deg);-webkit-transform:rotate(180deg);-ms-transform:rotate(180deg);transform:rotate(180deg);float:right;margin:-15px -6px 0 0;}
#pc1{-moz-transform:rotate(270deg);-o-transform:rotate(270deg);-webkit-transform:rotate(270deg);-ms-transform:rotate(270deg);transform:rotate(270deg);top:-420px;left:60px;}
#pc2{top:-740px;left:260px;}
#pc3{-moz-transform:rotate(90deg);-o-transform:rotate(90deg);-webkit-transform:rotate(90deg);-ms-transform:rotate(90deg);transform:rotate(90deg);top:-1000px;left:430px;}
#pc4{-moz-transform:rotate(180deg);-o-transform:rotate(180deg);-webkit-transform:rotate(180deg);-ms-transform:rotate(180deg);transform:rotate(180deg);top:-1220px;left:230px;}
#pc>div:empty+div:empty+div:empty+div:empty+#dcm{display:none;}
#sp>div:not(:empty)~#dcm{display:inline-block;}
#dcm{position:relative;top:-1420px;left:345px;padding:16px 0;height:18px;}
#dcm>input{width:1em;}
#dcm>div{margin:-16px 0;}
#df>div{border:0 none;padding:0;display:block;position:relative;width:50px;height:50px;padding:0;margin:0 0 -50px;line-height:1em;}
#fs1{-moz-transform:rotate(90deg);-o-transform:rotate(90deg);-webkit-transform:rotate(90deg);-ms-transform:rotate(90deg);transform:rotate(90deg);top:20px;left:80px;}
#fs2{-moz-transform:rotate(180deg);-o-transform:rotate(180deg);-webkit-transform:rotate(180deg);-ms-transform:rotate(180deg);transform:rotate(180deg);top:20px;left:670px;}
#fs3{-moz-transform:rotate(270deg);-o-transform:rotate(270deg);-webkit-transform:rotate(270deg);-ms-transform:rotate(270deg);transform:rotate(270deg);top:470px;left:670px;}
#fs4{top:470px;left:80px;}
#df>div>input{width:2em;}
#xzm{display:block;left:80px;position:relative;top:425px;width:580px;height:32px;margin:0 0 -32px;text-align:right;}
#xzm>button{height:28px;padding:0 8px;text-align:center;border:1px solid #FFF;margin:0 -1px 0 0;font-size:18px;}
#xzm>button:hover{cursor:pointer;}
#xzm>button[disabled]{display:none;}
#hup>div{position:relative;}
#hupj{display:block;top:160px;left:110px;height:32px;width:32px;margin:0 0 -32px 0;}
#hupj>input{width:20px;}
#hup1, #hup2{height:60px;margin:0 0 -60px 0;}
#hup1{left:140px;width:530px;}
#hup2{left:120px;width:570px;}
#hup1{top:140px;}
#hup2{top:250px;}
#hupm{display:block;height:32px;top:210px;left:140px;margin:0 0 -32px 0;width:530px;}
#hupms{width:300px;}
#hup2>:nth-child(3n+4){margin-left:12px;}
#hup1.p0>:nth-child(14),
#hup1.p1>:nth-child(11),
#hup1.p2>:nth-child(8),
#hup1.p3>:nth-child(5),
#hup1.p4>:nth-child(2){margin-left:16px;}
#hup>.p1>:nth-child(n+12),
#hup>.p2>:nth-child(n+9),
#hup>.p3>:nth-child(n+6),
#hup>.p4>:nth-child(n+3){margin-left:-8px;}
#hup>.p1>:nth-child(3n+12),
#hup>.p2>:nth-child(3n+9),
#hup>.p3>:nth-child(3n+6),
#hup>.p4>:nth-child(3n+3){margin-left:16px !important;}
#huangp{display:block;position:relative;top:235px;left:385px;width:4em;height:1em;margin:0 0 -1em;}#act:not(.sd)~#sd>#sdf{top:700px;}
#act.sd~#sd>#sdf{top:-50px;}
#sdf{-moz-transition:top 1s ease-out 0s;-o-transition:top 1s ease-out 0s;-webkit-transition:top 1s ease-out 0s;-ms-transition:top 1s ease-out 0s;transition:top 1s ease-out 0s;}
#act:not(.sd)~#sd>#sdm{top:-500px;}
#act.sd~#sd>#sdm{top:-50px;}
#sdm{-moz-transition:top 1s ease-out 0s;-o-transition:top 1s ease-out 0s;-webkit-transition:top 1s ease-out 0s;-ms-transition:top 1s ease-out 0s;transition:top 1s ease-out 0s;}
#sd{width:100%;height:100%;text-align:center;}
#sdf{position:relative;width:800px;height:600px;top:-50px;margin:0 0 -600px;left:0;background-color:#8C8;-moz-opacity:0.62;-webkit-opacity:0.62;-ms-opacity:0.62;-o-opacity:0.62;opacity:0.62;-moz-box-shadow:0 0 50px 50px #8C8;-webkit-box-shadow:0 0 50px 50px #8C8;-o-box-shadow:0 0 50px 50px #8C8;-ms-box-shadow:0 0 50px 50px #8C8;box-shadow:0 0 50px 50px #8C8;}
#sdm{position:relative;border:0 none;margin:auto;padding:32px 40px 64px;color:#FFF;background-color:#596;width:400px;-moz-opacity:1;-webkit-opacity:1;-o-opacity:1;-ms-opacity:1;opacity:1;-moz-border-radius:0 0 32px 32px;-webkit-border-radius:0 0 32px 32px;-o-border-radius:0 0 32px 32px;-ms-border-radius:0 0 32px 32px;border-radius:0 0 32px 32px;-moz-box-shadow:0 0 16px 16px #596;-webkit-box-shadow:0 0 16px 16px #596;-o-box-shadow:0 0 16px 16px #596;-ms-box-shadow:0 0 16px 16px #596;box-shadow:0 0 16px 16px #596;}
#sdm button{color:#CCC;}
#sdm button:hover{cursor:pointer;}
#sdm>div{text-align:left;margin:32px 0 0;}
#sdt, #sdb{text-align:center !important;}
#hpzs{display:inline-block;width:200px;text-align:left;}
#hz1, #hz2, #hz3{width:48px;display:inline-block;}
#hz2, #hz3{margin:0 0 0 28px;}
span.hz1~#hz1{color:#FFF;}
span.hz2~#hz2{color:#FFF;}
span.hz3~#hz3{color:#FFF;}
#sdb>button{margin:0 32px;color:#FFF;}
#qihf{display:none;}
#qf1, #qf2{width:64px;}
#qf3{width:80px;}
#qf2, #qf3{margin:0 0 0 96px;}
#qihf.qf1~#qf1{color:#FFF;}
#qihf.qf2~#qf2{color:#FFF;}
#qihf.qf3~#qf3{color:#FFF;}
#sdm>div.ppdd{color:#FFF;}
#dpsdi{color:#FFF;width:80px;text-align:center;}
#dpsd{display:inline-block;text-align:left;width:200px;}
#dpsd~button.ppdd{width:20px;text-align:center;}
#sdd{margin-right:40px;}
#sdp{margin-left:40px;}
#lp{display:block;left:80px;position:relative;top:425px;width:80px;height:24px;margin:0 0 -32px;text-align:left;}
#lp.d{color:#CCC;}
#lp:hover{cursor:pointer;}
#act.mv~*, #act.mv~*:hover, #act.mv~* *:hover{cursor:move !important;}
</style>
<script>var zhang=function(lb,sz){this.lb=lb;this.sz=sz;}
zhang.prototype.numhuir=2;zhang.prototype.zzhang=[7,9,9,9];zhang.prototype.zdir=["z","w","b","t"];var ww=new zhang(1,5);zhang.prototype.sethuir=function(){zhang.prototype.huir=new Array(zhang.prototype.numhuir);zhang.prototype.huir[0]=new zhang(this.lb,this.sz);for(var i=1;i<zhang.prototype.numhuir;i++){zhang.prototype.huir[i]=new zhang(zhang.prototype.huir[i-1].lb,zhang.prototype.huir[i-1].sz+1);if(zhang.prototype.huir[i].sz===10)
zhang.prototype.huir[i].sz=1;if(zhang.prototype.huir[i].lb===0)
if(zhang.prototype.huir[i].sz===5)
zhang.prototype.huir[i].sz=1;else if(zhang.prototype.huir[i].sz===8)
zhang.prototype.huir[i].sz=5;}
var d=$i("hxsm"),h=$i("hxsp"),t;while(d.firstChild)d.removeChild(d.firstChild);for(var i=0;i<zhang.prototype.numhuir;i++){t=zhang.prototype.huir[i].divtag();d.appendChild(t);h.className=(i>0?(h.className+" "):"")+t.className;}}
zhang.prototype.same=function(b){return this.lb===b.lb&&this.sz===b.sz;}
zhang.prototype.samehuir=function(){for(var i=0;i<zhang.prototype.numhuir;i++)
if(this.same(zhang.prototype.huir[i]))return true;return false;}
zhang.prototype.chr=function(){return zhang.prototype.zdir[this.lb]+this.sz;}
zhang.prototype.divtag=function(o){if(typeof(o)!=="undefined"&&o){var d=document.createElement("div");d.appendChild(this.divtag());d.appendChild(this.divtag());d.className="g2";return d;}
var d=document.createElement("div");d.className=zhang.prototype.zdir[this.lb]+this.sz;return d;}
zhang.prototype.dcdt=function(s){var i,j;for(i=0;i<=3;i++)
if(s.charAt(0)===zhang.prototype.zdir[i])break;this.lb=i
this.sz=s.charCodeAt(1)-48;}
var $i=function(id){return document.getElementById(id);};var callfunc=function(func){setTimeout(func,0);}
var zpos=0,ppos=0;var dapc=new zhang(0,0);var chty;var
ZH_G="杠",ZH_K="开",ZH_M="没",ZH_S="双",ZH_H="混",ZH_E="儿",ZH_I="吊",ZH_Z="捉",ZH_W="伍",ZH_3="本",ZH_L="龙",ZH_X="小",ZH_U="和",ZH_P="牌",ZH_N="碰",ZH_QX="取消";var
ZH_DNXB=["东","南","西","北"];var
ZH_SZ=["","一","二","三","四","五","六","七","八","九"];var
ZH_LB=["字","万","饼","条"];var
ZH_FJ=["","东风","南风","西风","北风","红中","发财","白板"];var
SDXZ=[0,100,150,200,250,300,350,400,450,500,600,700,800,900,1000,1200,1400,1600,1800,2000,2500,3000,4000];var clearButtons=function(){var x=$i("xzm");x.style.display="none";while(x.firstChild)
x.removeChild(x.firstChild);}
var setButtons=function(arr){clearButtons();var i,l=arr.length,d,x=$i("xzm");x.style.display="none";for(i=0;i<l;i++){d=document.createElement("button");d.innerHTML=arr[i].n;d.onclick=arr[i].f;if(typeof(arr[i].v)!=="undefined")
d.value=arr[i].v;x.appendChild(d);}
x.style.display="block";}
var tpzhuang=function(){this.nzhuang=0;this.dong=0;};tpzhuang.prototype.init=function(){this.nzhuang=1;this.dong=Math.floor(Math.random()*4)+1;};tpzhuang.prototype.print=function(){var i;for(i=1;i<=4;i++)
$i(["zc1","zc2","zc3","zc4"][i-1]).value=ZH_DNXB[(this.dong+4-i)%4];$i("qs").value=((this.nzhuang-1)-(this.nzhuang-1)%4)/4+1;$i("zf").value=ZH_DNXB[(this.nzhuang-1)%4];};var zhuang=new tpzhuang();var tppq=function(){var a=new Array(136);var i,j,k,l=0;for(i=0;i<=3;i++)
for(j=1;j<=zhang.prototype.zzhang[i];j++)
for(k=0;k<4;k++)
a[l++]=new zhang(i,j);for(i in a)
this[i]=a[i];this.length=136;this.pos=0;this.last=136;this.huir=136;}
tppq.prototype=Array.prototype;tppq.prototype.rp=function(){var i,j;var swap=function(a,b){var lb=a.lb,sz=a.sz;a.lb=b.lb;b.lb=lb;a.sz=b.sz;b.sz=sz;}
for(i=0;i<10;i++)
for(j=0;j<136;j++)
swap(this[j],this[Math.floor(Math.random()*(136-j))+j]);}
tppq.prototype.init=function(){this.rp();this.pos=0;this.last=136;this.huir=136;}
tppq.prototype.dhuir=function(){this.huir=136-2*(Math.floor(Math.random()*6+1)+Math.floor(Math.random()*6+1));this.printnum();return this[this.huir];}
tppq.prototype.num=function(){return Math.min(this.last,this.huir)-this.pos;}
tppq.prototype.getp=function(){var pz;if(this.num()>0)pz=this[this.pos++];else pz=null;this.printnum();return pz;}
tppq.prototype.getlp=function(){--this.last;if(this.last==this.huir)--this.last;if(this.last>this.huir)pz=this[this.last];else if(this.num()>0)pz=this[this.last];else pz=null;this.printnum();return pz;}
tppq.prototype.printnum=function(){var d=$i("sy"),n=this.num();d.value=n;d.className=n<20?"l20":"";}
var pq=new tppq;var dp=null;var autosort=true;var pos0x,pos0y,pos0n,len;var movelast=true;var move_over=function(e){if(dp===null)return;var a=$i("act");if(a.className.indexOf("mv")===-1)
a.className+=" mv";var
pos1x=e.screenX,pos1y=e.screenY,pos1n=Math.round((pos1x-pos0x)/36+pos0n),d=dp.parentNode,d0=dp.cloneNode(true);d.removeChild(dp);if(pos1n<0)pos1n=0;if(pos1n>=len)pos1n=len-1;if(pos1n===d.childNodes.length)d.appendChild(d0);else d.insertBefore(d0,d.childNodes[pos1n]);d0.onmouseup=move_up;dp=d0;}
var move_up=function(e){if(dp===null)return;var c=$i("act").className;$i("act").className=c.substring(0,c.length-3);var i,l=sp[3].pz(),a=dp.parentNode.childNodes;for(i=0;i<l;i++)sp[3][i].dcdt(a[i].className);if($i("act").className.indexOf("p4")!==-1){dap_wj_ro();pmove_ro();}
dp=null;}
var lp_switch=function(){this.className=this.className==="d"?"":"d";autosort=this.className!=="d";if(autosort){sp[3].sort();sp[3].print();if($i("act").className==="p4"){dap_wj_ro();pmove_ro();}}}
var pxinit=function(){$i("lp").onclick=lp_switch;$i("main_body").onmouseover=move_over;$i("main_body").onmouseup=move_up;var b=document.getElementsByTagName("body")[0];b.setAttribute("unselectable","on");b.onselectstart=function(){return false;};}
var pmove_d=function(event){if(dp!==null)return;dp=this;pos0x=event.screenX;pos0y=event.screenY;var i,l=sp[3].pz(),p=$i("su4").childNodes;for(i=0;i<l;i++)if(p[i]===this)pos0n=i;len=sp[3].pz();if(i===len-1)pos0x-=24;}
var pmove_ro=function(){var i,l=sp[3].pz(),p=$i("su4").childNodes;if(!movelast)l--;for(i=0;i<l;i++)p[i].onmousedown=pmove_d;}
var pmove_co=function(){var i,l=sp[3].pz(),p=$i("su4").childNodes;for(i=0;i<l;i++)p[i].onmousedown=null;}
var ba=function(){var i;for(i=0;i<=13;i++)this[i]=new zhang(0,0);this.pos=0;this.peng=0;this.gang=[false,false,false,false];}
ba.prototype.init=function(pos,a){var i;for(i=0;i<13;i++)
this[i]=a.getp();this[13]=new zhang(0,9);this.pos=pos;this.peng=0;this.gang=[false,false,false,false];if(pos!==4||autosort)this.sort();}
ba.prototype.length=14;ba.prototype.pz=function(){return ba.prototype.length-this.peng*3;}
ba.prototype.print=function(){var d=$i(["su1","su2","su3","su4"][this.pos-1]);while(d.firstChild)d.removeChild(d.firstChild);var i;for(i=0;i<this.length;i++){d.appendChild(this[i].divtag(!(i%3)&&i>2&&this.gang[(i-3)/3]));}
d.className="p"+this.peng;}
ba.prototype.sort=function(){var zhangcmp
zhangcmp=function(a,b){var as=a.lb===0&&a.sz===9;var bs=b.lb===0&&b.sz===9;if(as&&!bs)return 1000;else if(!as&&bs)return-1000;var ah=a.samehuir(),bh=b.samehuir();if(ah!==bh)return ah?-100:100;return-10*(a.lb-b.lb)+(a.sz-b.sz);}
var t=this.pz();var i,j;for(i=0;i<t-2;i++)for(j=i+1;j<t;j++)
if(zhangcmp(this[i],this[j])>0){var temp=this[i];this[i]=this[j];this[j]=temp;}}
var sp=[new ba(),new ba(),new ba(),new ba()];var qihuf=2;var pdhpl=function(){this.ky=false;this.mh=false;this.hd=0;this.zw=false;this.l=0;this.g=false;this.mc="";this.dx=0;this.j=new zhang(0,0);this.numwbt=[0,0,0,0];this.last=new zhang(0,0);}
ba.prototype.pdhp=function(g){var numwbt=[0,0,0,0],jiang=new zhang(0,0);var tiao=function(){var i,j;for(i=0;i<4;i++){this[i]=new Array(10);for(j=0;j<=9;j++)
this[i][j]=0;}
this.length=4;}
tiao.prototype=Array.prototype;tiao.prototype.copy=function(t){var i,j;for(i=0;i<4;i++)
for(j=0;j<=9;j++)
this[i][j]=t[i][j];this.length=4;}
var ba2tiao=function(a){var b=new tiao();var i;for(i=0;i<a.pz();i++)
if(a[i].samehuir())b[0][8]++;else{b[a[i].lb][a[i].sz]++;b[a[i].lb][0]++;}
return b;}
var t=ba2tiao(this);var last=this[this.pz()-1];var panduanl=function(a,huir){var i,f;for(i=1;i<=9;i++)if(a[i])break;if(i>9)return true;if(a[i]>=3){a[i]-=3;f=(panduanl(a,huir));a[i]+=3;if(f)return true;}else if(a[i]===2&&huir>=1){a[i]-=2;f=(panduanl(a,huir-1));a[i]+=2;if(f)return true;}
if(i<8&&a[i]>=1&&a[i+1]>=1&&a[i+2]>=1){a[i]--;a[i+1]--;a[i+2]--;f=(panduanl(a,huir));a[i]++;a[i+1]++;a[i+2]++;if(f)return true;}else{if(i<8&&a[i]>=1&&a[i+2]>=1&&huir>=1){a[i]--;a[i+2]--;f=(panduanl(a,huir-1));a[i]++;a[i+2]++;if(f)return true;}
if(i<9&&a[i]>=1&&a[i+1]>=1&&huir>=1){a[i]--;a[i+1]--;f=(panduanl(a,huir-1));a[i]++;a[i+1]++;if(f)return true;}}
if(huir>=2&&a[i]===1&&(i===9||a[i+1]===0)&&(i===8||a[i+2]===0)){a[i]--;f=(panduanl(a,huir-2));a[i]++;if(f)return true;}
return false;}
var panduanz=function(a){var u=[0,2,1,0,2],i,t=0;for(i=1;i<=7;i++)
t+=u[a[i]];return t;}
var panduanf=function(a){var h=[panduanz(a[0]),0,0,0];for(h[1]=(12-a[1][0])%3;h[0]+h[1]<=a[0][8];h[1]+=3)
for(h[2]=(12-a[2][0])%3;h[0]+h[1]+h[2]<=a[0][8];h[2]+=3){h[3]=a[0][8]-(h[0]+h[1]+h[2]);if(panduanl(a[1],h[1])&&panduanl(a[2],h[2])&&panduanl(a[3],h[3])){numwbt=h;return true;}}
return false;}
var xiaohu=function(t){var a=new tiao;a.copy(t);var i,j,f;for(i=0;i<4;i++)
for(j=1;j<=zhang.prototype.zzhang[i];j++)
if(a[i][j]>=2){a[i][j]-=2;a[i][0]-=2;jiang=new zhang(i,j);f=panduanf(a);a[i][j]+=2;a[i][0]+=2;if(f)return true;}else if(a[i][j]===1){a[i][j]--;a[i][0]--;a[0][8]--;jiang=new zhang(i,j);f=panduanf(a);a[i][j]++;a[i][0]++;a[0][8]++;if(f)return true;}
return false;}
var panduan=function(t,hd,zw,l,last){var pdr=function(ky,sh,ll){this.ky=ky;this.sh=sh;this.ll=ll;this.lb=ll===zhang.prototype.huir[0].lb;}
var hp=new zhang(0,8),ww=new zhang(1,5);var sh=false,ll=0;var lah=last.samehuir()?1:0;if(lah)last=new zhang(0,8);var rf=new pdr(false,0,0);if(zw)if(!last.same(ww)&&!last.same(hp))return rf;var a=new tiao(),c=new tiao(),b=new tiao();a.copy(t);c.copy(a);var sh_i,sh_l,sh_r;sh_l=hd?(zw?2:1):0;sh_r=hd?(Math.min(2,a[0][8]-lah)):0;for(sh_i=sh_r;sh_i>=sh_l;sh_i--){sh=sh_i===2;a.copy(c);if(hd&&!zw){a[last.lb][last.sz]--;if(!last.same(hp))a[last.lb][0]--;var i;for(i=0;i<sh_i;i++)a[0][8]--;}
if(hd&&zw){a[last.lb][last.sz]--;if(!last.same(hp))a[last.lb][0]--;a[0][8]-=2;}
if(!hd&&zw){a[last.lb][last.sz]--;if(!last.same(hp))a[last.lb][0]--;if(a[1][4]>0){a[1][4]--;a[1][0]--;}else a[0][8]--;if(a[1][6]>0){a[1][6]--;a[1][0]--;}else a[0][8]--;}
if(!l){if(sh_i===1){if(panduanf(a))return new pdr(true,sh_i,0);}
else{if(xiaohu(a))return new pdr(true,sh_i,0);}}else{b.copy(a);if(zhang.prototype.huir[0].lb!==0){ll=zhang.prototype.huir[0].lb;for(i=1;i<=9;i++)
if(!(!hd&&zw&&ll===1&&i>=4&&i<=6))
if(a[ll][i]>0){a[ll][i]--;a[ll][0]--;}
else a[0][8]--;if(a[0][8]>=0)
if(sh_i===1){if(panduanf(a))return new pdr(true,sh_i,ll);}
else{if(xiaohu(a))return new pdr(true,sh_i,ll);}}
for(ll=1;ll<=3;ll++)if(ll!==zhang.prototype.huir[0].lb){a.copy(b);for(i=1;i<=9;i++)
if(!(!hd&&zw&&ll===1&&i>=4&&i<=6))
if(a[ll][i]>0){a[ll][i]--;a[ll][0]--;}
else a[0][8]--;if(a[0][8]>=0)
if(sh_i===1){if(panduanf(a))return new pdr(true,sh_i,ll);}
else{if(xiaohu(a))return new pdr(true,sh_i,ll);}}}}
return rf;}
var daxiao=function(mh,hd,zw,l,lb,g){return((((zw?3:0)+(l?4:0)+(!zw&&!l?1:0))*(mh?2:1)*(hd?2:1)*(l&&lb?2:1))*(g?2:1));}
var mingming=function(mh,hd,zw,l,lb,g){var s="";if(g)s+=ZH_G+ZH_K;if(mh)s+=ZH_M+ZH_H+ZH_E;if(hd===2)s+=ZH_S;if(hd>0)s+=ZH_H+ZH_E;if(hd>0&&!zw)s+=ZH_I;if(zw&&(s===""||l))s+=ZH_Z;if(zw)s+=ZH_W+ZH_E;if(l&&lb)s+=ZH_3+ZH_H+ZH_E;if(l)s+=ZH_L;if(s==="")s=ZH_X+ZH_U;return s;}
var qihu=function(r){r.ky=(r.dx>=qihuf)||((qihuf===3)&&(r.g||r.mh));}
var xuanze=function(t,last){var a=new tiao();a.copy(t);var i;var r=new pdhpl();var mh=a[0][8]===0,hd,zw,l;for(i=7;i>=0;i--){hd=!!(i&1);zw=!!(i&2);l=!!(i&4);if(daxiao(mh,hd,zw,l,true)<=r.dx)continue;var e=panduan(a,hd,zw,l,last,g);if(e.ky){var n=daxiao(mh,hd,zw,l,e.lb,g);if(n>r.dx){r.dx=n;r.last=last;r.mh=mh;r.hd=e.sh;r.zw=zw;r.l=e.ll;r.g=g;r.mc=mingming(mh,e.sh,zw,l,e.lb,g);qihu(r);if(r.hd===1)r.j=new zhang(last.lb,last.sz);else r.j=new zhang(jiang.lb,jiang.sz);r.numwbt=[numwbt[0],numwbt[1],numwbt[2],numwbt[3]];}}}
return r;}
return xuanze(t,last);}
var hpxs=function(r,s){var i,j,l,len=s.pz();var huirlist=new Array(14);var hulist=new Array(14),hp=s.pz();var ht=new Array(4);var last=new zhang(r.last.lb,r.last.sz);if(last.samehuir())last=new zhang(0,8);for(i=0;i<4;i++){ht[i]=new Array(10);for(j=0;j<10;j++)
ht[i][j]=0;}
for(i=0,j=0;i<len;i++)
if(s[i].samehuir()){ht[0][8]++;huirlist[j++]=new zhang(s[i].lb,s[i].sz);}else ht[s[i].lb][s[i].sz]++;if(r.hd!==1)for(i=0;i<2;i++){if(ht[r.j.lb][r.j.sz]!==0){ht[r.j.lb][r.j.sz]--;hulist[--hp]=new zhang(r.j.lb,r.j.sz);}else{ht[0][8]--;hulist[--hp]=new zhang(0,8);}}else{hulist[--hp]=new zhang(last.lb,last.sz);hulist[--hp]=new zhang(0,8);ht[last.lb][last.sz]--;ht[0][8]--;}
if(r.hd===2){if(r.zw){hulist[--hp]=new zhang(0,8);hulist[--hp]=new zhang(last.lb,last.sz);}else{hulist[--hp]=new zhang(last.lb,last.sz);hulist[--hp]=new zhang(0,8);}
hulist[--hp]=new zhang(0,8);ht[last.lb][last.sz]--;ht[0][8]-=2;}else if(r.zw){var rm;for(i=6;i>=4;i--){if(i===5)rm=new zhang(last.lb,last.sz);else rm=new zhang(1,i);if(ht[rm.lb][rm.sz]!==0){hulist[--hp]=new zhang(rm.lb,rm.sz);ht[rm.lb][rm.sz]--;}else{hulist[--hp]=new zhang(0,8);ht[0][8]--;}}}
if(r.l!==0)for(i=9;i>=1;i--)
if(!(r.zw&&r.l===1&&(i in[4,5,6])&&r.hd!==2))
if(ht[r.l][i]!==0){hulist[--hp]=new zhang(r.l,i);ht[r.l][i]--;}else{hulist[--hp]=new zhang(0,8);ht[0][8]--;}
for(i=1;i<=7;i++)if(ht[0][i]!==0)
for(j=0;j<3;j++)if(ht[0][i]!==0){hulist[--hp]=new zhang(0,i);ht[0][i]--;}else{hulist[--hp]=new zhang(0,8);ht[0][8]--;}
for(l=1;l<=3;l++)(function fxs(){var i,j,k,f=true;var htb=new Array(10),n=r.numwbt[l];for(i=0;i<=9;i++)htb[i]=ht[l][i];for(k=9;k>=1;k--)if(ht[l][i=k]!==0){f=false;if(ht[l][i]+r.numwbt[l]>=3){for(j=0;j<3;j++)if(ht[l][i]!==0){hulist[--hp]=new zhang(l,i);ht[l][i]--;}else{hulist[--hp]=new zhang(0,8);r.numwbt[l]--;}
if(fxs())
return true;hp+=3;r.numwbt[l]=n;for(j=0;j<=9;j++)ht[l][j]=htb[j];}
if(i===9)continue;if(i===8)i=7;if(((ht[l][i]>0)?1:0)+((ht[l][i+1]>0)?1:0)+((ht[l][i+2]>0)?1:0)+(r.numwbt[l])>=3){for(j=i+2;j>=i;j--)if(ht[l][j]!==0){hulist[--hp]=new zhang(l,j);ht[l][j]--;}else{hulist[--hp]=new zhang(0,8);r.numwbt[l]--;}
if(fxs())
return true;hp+=3;r.numwbt[l]=n;for(j=0;j<=9;j++)ht[l][j]=htb[j];}}
return f;})();while(hp>0)hulist[--hp]=new zhang(0,8);var d=$i("hup2").childNodes;for(j=0,i=0;i<len;i++)
if(!hulist[i].same(new zhang(0,8)))
d[i].className=hulist[i].divtag().className;else
d[i].className=huirlist[j++].divtag().className;}
var tpfs=function(){this[0]=this[1]=this[2]=this[3]=0;};tpfs.prototype.init=function(){var i;for(i=0;i<4;i++)
this[i]=250;};tpfs.prototype.print=function(){var i;for(i=0;i<4;i++)
$i(["scr1","scr2","scr3","scr4"][i]).value=this[i];};tpfs.prototype.df=function(n,p,g){this[p]+=4*n;var i;for(i=0;i<4;i++)
this[i]-=n;this.print();};var fs=new tpfs();var ainit=function(){callfunc(binit);callfunc(ginit)
callfunc(minit);callfunc(pxinit);}
var minit=function(){zhuang.init();fs.init();setTimeout(jinit,0);}
var jinit=function(){zhuang.print();fs.print();cqinit();pq.init();pq.dhuir().sethuir();var i;for(i=0;i<4;i++){sp[i].init(i+1,pq);sp[i].print();}
clearpc();clearButtons();zpos=zhuang.nzhuang+zhuang.dong-3;callfunc(zhuap);}
var binit=function(){$i("hxsm").ondblclick=function(e){if(!e.shiftKey)return;var s=$i("su");s.className=(s.className==="xs"?"":"xs");}}
var dap_wj_ro=function(){var i,l=sp[3].pz(),p=$i("su4").childNodes;for(i=0;i<l;i++)p[i].onclick=dap_wj_i;}
var dap_wj_co=function(){var i,l=sp[3].pz(),p=$i("su4").childNodes;for(i=0;i<l;i++)p[i].onclick=null;}
var dap_wj=function(){movelast=true;if(chty!==3){var i,j,c,s=sp[3],l=Array(3),n=0,b=[];for(i=0;i<14;i++)if(!s[i].samehuir()){for(j=i,c=0;j<14;c+=(s[j++].same(s[i]))?1:0);if(c===4)l[n++]=new zhang(s[i].lb,s[i].sz);}
if(n===1)b[b.length]={n:ZH_G+ZH_P,f:xm_ag_wj_i,v:l[0].divtag().className};else for(i=0;i<n;i++)
b[b.length]={n:ZH_G+(l[i].lb!==0?(ZH_SZ[l[i].sz]+ZH_LB[l[i].lb]):(ZH_FJ[l[i].sz])),f:xm_ag_wj_i,v:l[i].divtag().className}
if(s.pdhp(chty===2).ky){b[b.length]={n:ZH_U+ZH_P,f:hup_wj_i};movelast=false;}
if(b.length>0)setButtons(b);}
comchose(sp[3]);dap_wj_ro();pmove_ro();}
var xm_ag_wj_i=function(){clearButtons();dap_wj_co();pmove_co();dapc.dcdt(this.value);callfunc(xm_agang);}
var dap_wj_i=function(){clearButtons();dap_wj_co();pmove_co();dapc.dcdt(this.className);callfunc(dac);}
var hup_wj_i=function(){clearButtons();dap_wj_co();pmove_co();callfunc(hup);}
var peng_wj_i=function(){clearButtons();callfunc(peng);}
var dmgang_wj_i=function(){clearButtons();callfunc(dmgang);}
var pgqx_wj_i=function(){clearButtons();callfunc(pgqx);}
var pg_wj=function(){var i,c;for(c=0,i=0;i<sp[3].pz();i++)
if(sp[3][i].same(dapc))c++;if(c===3)
setButtons([{n:ZH_N+ZH_P,f:peng_wj_i},{n:ZH_G+ZH_P,f:dmgang_wj_i},{n:ZH_QX,f:pgqx}]);else
setButtons([{n:ZH_N+ZH_P,f:peng_wj_i},{n:ZH_QX,f:pgqx_wj_i}]);}
var al;var cqinit=function(){al=[[28,4,4,4,4,4,4,4,0,0],[36,4,4,4,4,4,4,4,4,4],[36,4,4,4,4,4,4,4,4,4],[36,4,4,4,4,4,4,4,4,4]];}
var expp=function(z){al[z.lb][z.sz]--;al[z.lb][0]--;}
var
sx,st,nz;var
FCOUNT=200,DCOUNT,GCOUNT=50,W46COUNT;var comchose=function(s){var i,j;var v=new Array(4);var h=new Array(4);var a=new Array(4);{for(i=0;i<4;i++){v[i]=new Array(10);h[i]=new Array(10);a[i]=new Array(10);for(j=0;j<10;j++){h[i][j]=0;a[i][j]=al[i][j];v[i][j]=0;}}
for(i=0;i<s.pz();i++)
if(!s[i].samehuir()){h[s[i].lb][s[i].sz]++;a[s[i].lb][s[i].sz]--;}else{h[0][8]++;a[0][8]--;}
for(i=0;i<zhang.prototype.numhuir;i++)
a[zhang.prototype.huir[i].lb][zhang.prototype.huir[i].sz]=0;sx=pq.num();for(st=0,i=0;i<4;i++)
st+=a[i][0];nz=[0,0,0,0,0];for(i=0;i<4;i++)
for(j=1;j<=(i===0?7:9);j++)
nz[h[i][j]]++;DCOUNT=10/Math.pow(2,nz[2]);W46COUNT=(h[0][8]===0)?16:10-(h[0][8]>4)?4:0;}
{inusez(v[0],h[0],a[0]);inusel(v[1],h[1],a[1],true);inusel(v[2],h[2],a[2],false);inusel(v[3],h[3],a[3],false);for(i=0;i<zhang.prototype.numhuir;i++)
v[zhang.prototype.huir[i].lb][zhang.prototype.huir[i].sz]=Math.min();}
{var m=Math.min(),p=new zhang(0,0);for(i=0;i<s.pz();i++)
if(v[s[i].lb][s[i].sz]<m){m=v[s[i].lb][s[i].sz];p.lb=s[i].lb;p.sz=s[i].sz;}}
return p;}
var dnag=function(s,z){var i,j;var v=new Array(4);var h=new Array(4);var a=new Array(4);{for(i=0;i<4;i++){v[i]=new Array(10);h[i]=new Array(10);a[i]=new Array(10);for(j=0;j<10;j++){h[i][j]=0;a[i][j]=al[i][j];v[i][j]=0;}}
for(i=0;i<s.pz();i++)
if(!s[i].samehuir()){h[s[i].lb][s[i].sz]++;a[s[i].lb][s[i].sz]--;}else{h[0][8]++;a[0][8]--;}
for(i=0;i<zhang.prototype.numhuir;i++)
a[zhang.prototype.huir[i].lb][zhang.prototype.huir[i].sz]=0;sx=pq.num();for(st=0,i=0;i<4;i++)
st+=a[i][0];nz=[0,0,0,0,0];for(i=0;i<4;i++)
for(j=1;j<=(i===0?7:9);j++)
nz[h[i][j]]++;DCOUNT=10/Math.pow(2,nz[2]);W46COUNT=(h[0][8]===0)?16:10-(h[0][8]>4)?4:0;}
var sc1,sc2,ag;ag=h[z.lb][z.sz]===4;if(z.lb===0)
sc1=inusez(v[0],h[0],a[0]);else
sc1=inusel(v[z.lb],h[z.lb],a[z.lb],z.lb===1);h[z.lb][z.sz]=0;if(z.lb===0)
sc2=inusez(v[0],h[0],a[0]);else
sc2=inusel(v[z.lb],h[z.lb],a[z.lb],z.lb===1);if(ag){if(sc2>sc1-4*FCOUNT-5*GCOUNT)return true;}
else{if(sc2>sc1-FCOUNT-GCOUNT)return true;}
return false;}
var dnpg=function(s,z){var i,j;var v=new Array(4);var h=new Array(4);var a=new Array(4);{for(i=0;i<4;i++){v[i]=new Array(10);h[i]=new Array(10);a[i]=new Array(10);for(j=0;j<10;j++){h[i][j]=0;a[i][j]=al[i][j];v[i][j]=0;}}
for(i=0;i<s.pz();i++)
if(!s[i].samehuir()){h[s[i].lb][s[i].sz]++;a[s[i].lb][s[i].sz]--;}else{h[0][8]++;a[0][8]--;}
for(i=0;i<zhang.prototype.numhuir;i++)
a[zhang.prototype.huir[i].lb][zhang.prototype.huir[i].sz]=0;sx=pq.num();for(st=0,i=0;i<4;i++)
st+=a[i][0];nz=[0,0,0,0,0];for(i=0;i<4;i++)
for(j=1;j<=(i===0?7:9);j++)
nz[h[i][j]]++;DCOUNT=10/Math.pow(2,nz[2]);W46COUNT=(h[0][8]===0)?16:10-(h[0][8]>4)?4:0;}
var sc1,sc2,sc3,g;if(z.lb===0)
sc1=inusez(v[0],h[0],a[0]);else
sc1=inusel(v[z.lb],h[z.lb],a[z.lb],z.lb===1);h[z.lb][z.sz]-=2;if(z.lb===0)
sc2=inusez(v[0],h[0],a[0]);else
sc2=inusel(v[z.lb],h[z.lb],a[z.lb],z.lb===1);if(h[z.lb][z.sz]===1){h[z.lb][z.sz]--;if(z.lb===0)
sc3=inusez(v[0],h[0],a[0]);else
sc3=inusel(v[z.lb],h[z.lb],a[z.lb],z.lb===1);if(sc3>sc1-3*FCOUNT-4*GCOUNT)return"g";}
if(sc2>sc1-2*FCOUNT)return"p";return false;}
var kz=function(s){return s/4;}
var gp=function(a){return 1-Math.pow(1-kz(sx)/st/4,a);}
var gpp=function(a){return 1-Math.pow(1-kz(sx)/st/4*1.2,a);}
var uj=function(){var i,r=1,l=arguments.length;for(i=0;i<l;i++)r*=(1-arguments[i]);return 1-r;}
var inusez=function(v,s,a){var i,u,m=0;for(i=0;i<7;i++)switch(s[i]){case 1:u=gp(a[i])*gpp(a[i]-1);v[i]=FCOUNT*u+DCOUNT*(1-u)*gp(a[i]);m+=v[i]*1;break;case 2:u=gpp(a[i]);v[i]=FCOUNT*u+DCOUNT;m+=v[i]*2;break;case 3:v[i]=FCOUNT+gp(a[i])*GCOUNT;m+=v[i]*3;break;case 4:v[i]=FCOUNT+GCOUNT;m+=v[i]*4;break;}
return m;};var inusel=function(v,s,a,w){var acpy=function(a,b){for(i=0;i<10;i++)a[i]=b[i];}
var l=new Array(10),r=new Array(10),m=Math.max(),i;for(i=1;i<10;i++)l[i]=Math.min();var sv=function(v,t){if(t<m)return;m=t;acpy(r,v);}
var inuselr=function(v,s,t){var v_=new Array(10),s_=new Array(10);var v__=new Array(10),s__=new Array(10);var sc1,sc2;var i,u;for(i=1;i<10;i++)if(s[i]!==0)break;if(i===10)sv(v,t);else{acpy(v_,v);acpy(s_,s);acpy(v,v_);acpy(s,s_);if(s[i]===1){u=uj(gp(a[i])*gp(a[i]-1),(i<=7)?gp(a[i+1])*gp(a[i+2]):0,(i>=3)?gp(a[i-1])*gp(a[i-2]):0,(i<=8&&i>=2)?gp(a[i-1])*gp(a[i+1]):0);sc1=FCOUNT*u+DCOUNT*(1-u)*gp(a[i]);if(w&&i===4||i===6)sc1+=W46COUNT/2;v[i]=Math.min(v[i],sc1);s[i]=0;inuselr(v,s,t+sc1);}else
if(s[i]===2){u=uj((i<=7)?gp(a[i+1])*gp(a[i+2]):0,(i>=3)?gp(a[i-1])*gp(a[i-2]):0,(i<=8&&i>=2)?gp(a[i-1])*gp(a[i+1]):0);sc1=FCOUNT*(gpp(a[i])+(1-gpp(a[i]))*u)+DCOUNT;v[i]=Math.min(v[i],sc1);s[i]=0;inuselr(v,s,t+sc1*2);}else
if(s[i]===3){sc1=FCOUNT+gp(a[i])*GCOUNT+DCOUNT/2;v[i]=Math.min(v[i],sc1);s[i]=0;inuselr(v,s,t+sc1*3);}else
if(s[i]===4){sc1=FCOUNT+GCOUNT;v[i]=Math.min(v[i],sc1);s[i]=0;inuselr(v,s,t+sc1*4);}
acpy(v,v_);acpy(s,s_);if(i<=7)if(s[i+1]>0&&s[i+2]>0){sc1=FCOUNT;v[i]=Math.min(v[i],sc1);v[i+1]=Math.min(v[i+1],sc1);v[i+2]=Math.min(v[i+2],sc1);s[i]--;s[i+1]--;s[i+2]--;inuselr(v,s,t+sc1*3);}
acpy(v,v_);acpy(s,s_);if(i<=8)if(s[i+1]>0){if(i===1)u=gp(a[i+2]);else if(i===8)u=gp(a[i-1]);else u=gp(a[i-1]+a[i+2]);sc1=(1-u)*gp(a[i])*gpp(a[i]-1)*FCOUNT+u*FCOUNT;sc2=(1-u)*gp(a[i+1])*gpp(a[i+1]-1)*FCOUNT+u*FCOUNT;v[i]=Math.min(v[i],sc1);v[i+1]=Math.min(v[i+1],sc2);s[i]--;s[i+1]--;inuselr(v,s,t+sc1+sc2);}
acpy(v,v_);acpy(s,s_);if(i<=7)if(s[i+1]===0&&s[i+2]>0){var u1,u2;u=gp(a[i+1]);u1=uj(u,(i>=3)?gp(a[i-1])*gp(a[i-2]):0);u2=uj(u,(i<=5)?gp(a[i+3])*gp(a[i+4]):0);sc1=(1-u1)*gp(a[i])*gpp(a[i]-1)*FCOUNT+(1-u1)*gp(a[i])*(1-gpp(a[i]-1))*DCOUNT+u1*FCOUNT;sc2=(1-u2)*gp(a[i+2])*gpp(a[i+2]-1)*FCOUNT+(1-u2)*gp(a[i+2])*(1-gpp(a[i+2]-1))*DCOUNT+u2*FCOUNT;v[i]=Math.min(v[i],sc1);v[i+2]=Math.min(v[i+2],sc2);s[i]--;s[i+2]--;inuselr(v,s,t+sc1+sc2);}
acpy(v,v_);acpy(s,s_);if(i<=7)if(s[i+1]>0&&s[i+2]>0){sc1=FCOUNT;v[i]=Math.min(v[i],sc1);v[i+1]=Math.min(v[i+1],sc1);v[i+2]=Math.min(v[i+2],sc1);s[i]--;s[i+1]--;s[i+2]--;acpy(v__,v);acpy(s__,s);if(s[i]>0&&i<=6){u=uj(gp(a[i])*gp(a[i]-1),gp(a[i+1])*gp(a[i+2]),gp(a[i-1])*gp(a[i-2]),gp(a[i-1])*gp(a[i+1]),gp(a[i])*gp(a[i+3]));sc2=FCOUNT*u+DCOUNT*(1-u)*gp(a[i]);v[i]=Math.min(v[i],sc2);s[i]--;inuselr(v,s,t+sc1*3+sc2);}
acpy(v,v__);acpy(s,s__);if(s[i+1]>0&&i>=2&&i<=6){u=uj(gp(a[i])*gp(a[i]-1),gp(a[i+1])*gp(a[i+2]),gp(a[i-1])*gp(a[i-2]),gp(a[i-1])*gp(a[i+1]),gp(a[i-1])*gp(a[i+3]));sc2=FCOUNT*u+DCOUNT*(1-u)*gp(a[i+1]);v[i+1]=Math.min(v[i+1],sc2);s[i+1]--;inuselr(v,s,t+sc1*3+sc2);}
acpy(v,v__);acpy(s,s__);if(s[i+2]>0&&i>=2){u=uj(gp(a[i])*gp(a[i]-1),gp(a[i+1])*gp(a[i+2]),gp(a[i-1])*gp(a[i-2]),gp(a[i-1])*gp(a[i+1]),gp(a[i-1])*gp(a[i+2]));sc2=FCOUNT*u+DCOUNT*(1-u)*gp(a[i+2]);v[i+2]=Math.min(v[i+2],sc2);s[i+2]--;inuselr(v,s,t+sc1*3+sc2);}}
acpy(v,v_);acpy(s,s_);if(i<=8)if(s[i]>=2&&s[i+1]>=1&&(i===8||s[i+2]===0)){sc1=FCOUNT*gpp(a[i])+DCOUNT;if(i===1)u=gp(a[i+2]);else if(i===8)u=gp(a[i-1]);else u=gp(a[i-1]+a[i+2]);sc2=(1-u)*gp(a[i+1])*gpp(a[i+1]-1)*FCOUNT+(1-u)*gp(a[i+1])*(1-gpp(a[i+1]-1))*DCOUNT+u*FCOUNT;v[i]=Math.min(v[i],sc1);v[i+1]=Math.min(v[i+1],sc2);s[i]-=2;s[i+1]--;inuselr(v,s,t+sc1+sc2+Math.max(sc1,sc2));}
acpy(v,v_);acpy(s,s_);if(i<=8)if(s[i+1]>=2&&(i===8||s[i+2]===0)){if(i===1)u=gp(a[i+2]);else if(i===8)u=gp(a[i-1]);else u=gp(a[i-1]+a[i+2]);sc1=(1-u)*gp(a[i])*gpp(a[i]-1)*FCOUNT+(1-u)*gp(a[i])*(1-gpp(a[i]-1))*DCOUNT+u*FCOUNT;sc2=FCOUNT*gpp(a[i+1])+DCOUNT;v[i]=Math.min(v[i],sc1);v[i+1]=Math.min(v[i+1],sc2);s[i]--;s[i+1]-=2;inuselr(v,s,t+sc1+sc2+Math.max(sc1,sc2));}
acpy(v,v_);acpy(s,s_);if(i<=7)if(s[i]>=2&&s[i+2]>=1&&s[i+1]===0){sc1=FCOUNT*gpp(a[i])+DCOUNT;u=gp(a[i+1]);sc2=(1-u)*gp(a[i+2])*gpp(a[i+2]-1)*FCOUNT+(1-u)*gp(a[i+2])*(1-gpp(a[i+2]-1))*DCOUNT+u*FCOUNT;v[i]=Math.min(v[i],sc1);v[i+2]=Math.min(v[i+2],sc2);s[i]-=2;s[i+2]--;inuselr(v,s,t+sc1+sc2+Math.max(sc1,sc2));}
acpy(v,v_);acpy(s,s_);if(i<=7)if(s[i+2]>=2&&s[i+1]===0){u=gp(a[i+1]);sc1=(1-u)*gp(a[i])*gpp(a[i]-1)*FCOUNT+(1-u)*gp(a[i])*(1-gpp(a[i]-1))*DCOUNT+u*FCOUNT;sc2=FCOUNT*gpp(a[i+2])+DCOUNT;v[i]=Math.min(v[i],sc1);v[i+2]=Math.min(v[i+2],sc2);s[i]--;s[i+2]-=2;inuselr(v,s,t+sc1+sc2+Math.max(sc1,sc2));}
acpy(v,v_);acpy(s,s_);if(i<=6)if(s[i+1]>0&&s[i+2]>0&&s[i+3]>0){var sc;u=uj((i>=3)?gp(a[i-1])*gp(a[i-2]):0,(i>=2)?gp(a[i-1])*gp(a[i+1]):0,gp(a[i+1])*gp(a[i+2]),(i<=5)?gp(a[i+2])*gp(a[i+4]):0,(i<=4)?gp(a[i+4])*gp(a[i+5]):0);sc1=(1-u)*gp(a[i])*gpp(a[i]-1)*FCOUNT+(1-u)*gp(a[i])*(1-gpp(a[i]-1))*DCOUNT+u*FCOUNT;sc2=(1-u)*gp(a[i+3])*gpp(a[i+3]-1)*FCOUNT+(1-u)*gp(a[i+3])*(1-gpp(a[i+3]-1))*DCOUNT+u*FCOUNT;sc=FCOUNT;v[i]=Math.min(v[i],sc1);v[i+1]=Math.min(v[i+1],sc);v[i+2]=Math.min(v[i+2],sc);v[i+3]=Math.min(v[i+3],sc2);s[i]--;s[i+1]--;s[i+2]--;s[i+3]--;inuselr(v,s,t+sc*3+Math.max(sc1,sc2));}
acpy(v,v_);acpy(s,s_);if(i<=5)if(s[i+1]>0&&s[i+2]>0&&s[i+3]>0&&s[i+4]>0){var sc3,sc4,sc;u=uj((i>=2)?gp(a[i-1]):0,gp(a[i+2]),(i<=4)?gp(a[i+5]):0);sc1=(1-u)*gp(a[i])*gpp(a[i]-1)*FCOUNT+(1-u)*gp(a[i])*(1-gpp(a[i]-1))*DCOUNT+u*FCOUNT;sc2=(1-u)*gp(a[i+1])*gpp(a[i+1]-1)*FCOUNT+(1-u)*gp(a[i+1])*(1-gpp(a[i+1]-1))*DCOUNT+u*FCOUNT;sc3=(1-u)*gp(a[i+2])*gpp(a[i+2]-1)*FCOUNT+(1-u)*gp(a[i+2])*(1-gpp(a[i+2]-1))*DCOUNT+u*FCOUNT;sc4=(1-u)*gp(a[i+3])*gpp(a[i+3]-1)*FCOUNT+(1-u)*gp(a[i+3])*(1-gpp(a[i+3]-1))*DCOUNT+u*FCOUNT;sc=FCOUNT;v[i]=Math.min(v[i],sc1);v[i+1]=Math.min(v[i+1],sc2);v[i+2]=Math.min(v[i+2],sc);v[i+3]=Math.min(v[i+3],sc3);v[i+4]=Math.min(v[i+4],sc4);s[i]--;s[i+1]--;s[i+2]--;s[i+3]--;s[i+4]--;inuselr(v,s,t+sc*3+Math.max(sc1+sc2,sc1+sc3,sc1+sc4,sc2+sc3,sc2+sc4,sc3+sc4));}
acpy(v,v_);acpy(s,s_);if(i<=5)if(s[i+2]>0&&s[i+4]>0&&s[i+1]===0&&s[i+3]===0){var u1,u2,u3,sc3;u1=gp(a[i+1]);u3=gp(a[i+3]);u2=uj(u1,u3);sc1=(1-u1)*gp(a[i])*gpp(a[i]-1)*FCOUNT+(1-u1)*gp(a[i])*(1-gpp(a[i]-1))*DCOUNT+u1*FCOUNT;sc2=(1-u2)*gp(a[i+2])*gpp(a[i+2]-1)*FCOUNT+(1-u2)*gp(a[i+2])*(1-gpp(a[i+2]-1))*DCOUNT+u2*FCOUNT;sc3=(1-u3)*gp(a[i+4])*gpp(a[i+4]-1)*FCOUNT+(1-u3)*gp(a[i+4])*(1-gpp(a[i+4]-1))*DCOUNT+u3*FCOUNT;v[i]=Math.min(v[i],sc1);v[i+2]=Math.min(v[i+2],sc2);v[i+4]=Math.min(v[i+4],sc3);s[i]--;s[i+2]--;s[i+4]--;inuselr(v,s,t+sc1+sc2+sc3);}
acpy(v,v_);acpy(s,s_);if(i===1)if(s[1]>0&&s[2]>0&&s[4]>0&&s[3]===0){var sc3,u1,u2,u3;u2=gp(a[3]);sc2=(1-u2)*gp(a[2])*gpp(a[2]-1)*FCOUNT+(1-u2)*gp(a[2])*(1-gpp(a[2]-1))*DCOUNT+u2*FCOUNT;u1=gp(a[1])*gp(a[1]-1);sc1=FCOUNT*u1+DCOUNT*(1-u1)*gp(a[1]);u3=uj(gp(a[4])*gp(a[4]-1),gp(a[5])*gp(a[6]));sc3=FCOUNT*u3+DCOUNT*(1-u3)*gp(a[4]);v[1]=Math.min(v[1],sc1);v[2]=Math.min(v[2],sc2);v[4]=Math.min(v[4],sc3);s[1]--;s[2]--;s[4]--;inuselr(v,s,t+sc1+sc2+sc3);}
acpy(v,v_);acpy(s,s_);if(i===6)if(s[6]>0&&s[8]>0&&s[9]>0&&s[7]===0){var sc3,u1,u2,u3;u2=gp(a[7]);sc2=(1-u2)*gp(a[8])*gpp(a[8]-1)*FCOUNT+(1-u2)*gp(a[8])*(1-gpp(a[8]-1))*DCOUNT+u2*FCOUNT;u1=gp(a[9])*gp(a[9]-1);sc1=FCOUNT*u1+DCOUNT*(1-u1)*gp(a[9]);u3=uj(gp(a[6])*gp(a[6]-1),gp(a[5])*gp(a[4]));sc3=FCOUNT*u3+DCOUNT*(1-u3)*gp(a[6]);v[9]=Math.min(v[9],sc3);v[8]=Math.min(v[8],sc2);v[6]=Math.min(v[6],sc1);s[9]--;s[8]--;s[6]--;inuselr(v,s,t+sc1+sc2+sc3);}
acpy(v,v_);acpy(s,s_);if(w&&i===4&&s[6]>0&&s[5]===0){var u1,u2;u=gp(a[i+1]);u1=uj(u,gp(a[2])*gp(a[3]),gp(a[4])*gpp(a[4]-1));u2=uj(u,gp(a[7])*gp(a[8]),gp(a[6])*gpp(a[6]-1));sc1=u1*FCOUNT;sc2=u2*FCOUNT;v[4]=Math.min(v[4],sc1+W46COUNT);v[6]=Math.min(v[6],sc2+W46COUNT);s[4]--;s[6]--;inuselr(v,s,t+2*W46COUNT+sc1+sc2);}
acpy(v,v_);acpy(s,s_);}}
inuselr(l,s,0);acpy(v,r);return m;}
var timer_dn,timeout_dn=2;var dap_dn=function(){setTimeout(function(){timer_dn=true},SDXZ[timeout_dn]);timer_dn=false;var s=sp[zpos];if(s.pdhp(chty===2).ky){callfunc(hup_dn);}else{var i,j,c;for(i=0;i<14;i++)if(!s[i].samehuir()){for(j=i,c=0;j<14;c+=(s[j++].same(s[i]))?1:0);if(c===4)if(dnag(s,s[i])){dapc=new zhang(s[i].lb,s[i].sz);callfunc(xm_agang_dn);return;}}
var d=comchose(s);dapc=new zhang(d.lb,d.sz);callfunc(dac_dn);}}
var pg_dn=function(){var s=sp[ppos];var h=dnpg(s,dapc);var i,c;for(c=0,i=0;i<s.pz();i++)
if(s[i].same(dapc))c++;if(c===3&&h==="g")callfunc(dmgang);else if(h==="p")callfunc(peng);else callfunc(pgqx);}
hup_dn=function(){if(timer_dn)callfunc(hup);else setTimeout(hup_dn,10);}
xm_agang_dn=function(){if(timer_dn)callfunc(xm_agang);else setTimeout(xm_agang_dn,10);}
dac_dn=function(){if(timer_dn)callfunc(dac);else setTimeout(dac_dn,10);}
var pg_m=function(n){var pos=ppos,z=new zhang(dapc.lb,dapc.sz);var i,j,s=sp[pos],l=s.pz();for(i=0;i<n;i++){for(j=0;j<l;j++)if(s[j].same(z))break;for(;j<l-1;j++)s[j]=new zhang(s[j+1].lb,s[j+1].sz);s[j]=new zhang(z.lb,z.sz);}}
var peng=function(){var s=sp[ppos];s[s.pz()-1]=new zhang(dapc.lb,dapc.sz);rmpc();pg_m(2);s.peng++;s.print();zpos=ppos;chty=3;expp(dapc);expp(dapc);callfunc(dap);}
var dmgang=function(){var s=sp[ppos];rmpc();pg_m(3);s.peng++;s.gang[4-s.peng]=true;zpos=ppos;fs.df(1,ppos,true);expp(dapc);expp(dapc);expp(dapc);callfunc(zhuagd);}
var xm_agang=function(){var i,s=sp[zpos],l=s.pz(),c=0;if(zpos!==3||autosort)s.sort();for(i=0;i<l;i++)if(s[i].same(dapc))c++;if(c===4)callfunc(angang);else callfunc(xmgang);}
var xmgang=function(){var i,s=sp[ppos=zpos];for(i=4-s.peng;i<4;i++)if(s[i*3+3].same(dapc))s.gang[i]=true;pg_m(1);fs.df(1,ppos,true);expp(dapc);callfunc(zhuagd);}
var angang=function(){var i,s=sp[ppos=zpos];pg_m(4);i=++s.peng;s.gang[4-i]=true;s[14-i*3]=new zhang(0,0);fs.df(2,ppos,true);expp(dapc);expp(dapc);expp(dapc);expp(dapc);callfunc(zhuagd);}
var rmpc=function(){var d=$i(["pc1","pc2","pc3","pc4"][zpos]);var a=d.childNodes,l=a.length;d.removeChild(a[l-1]);}
var pgqx=function(){callfunc(zhuap);}
var hup=function(){var s=sp[zpos],r=s.pdhp(chty===2);$i(["su1","su2","su3","su4"][zpos]).className+=" xs";$i("hupwz").value=ZH_DNXB[(zhuang.dong+3-zpos)%4];$i("hupms").value=r.mc+"("+r.dx+")";var hps=$i("hup1"),hps2=$i("hup2"),spn=$i(["su1","su2","su3","su4"][zpos]);hps.innerHTML=spn.innerHTML;hps.className=spn.className;hps2.innerHTML=spn.innerHTML;hps2.className=spn.className;hpxs(r,s);$i("act").className="h2";fs.df(r.dx,zpos,false);if((zhuang.dong+3-zpos)%4!==(zhuang.nzhuang-1)%4)
zhuang.nzhuang++;callfunc(ctnj);}
var huangp=function(){$i("act").className="h1";callfunc(ctnj);}
var ctnj=function(){if(zhuang.nzhuang>16)
setButtons([{n:"重开",f:minit}]);else
setButtons([{n:"继续",f:jinit}]);}
var zhuap=function(){var z=pq.getp();if(z===null){callfunc(huangp);return;}
zpos=(zpos+3)%4;sp[zpos][sp[zpos].pz()-1]=z;sp[zpos].print();chty=1;callfunc(dap)}
var zhuagd=function(){var z=pq.getlp(),f=true;if(z===null){callfunc(huangp);z=new zhang(0,9);f=false;}
zpos=ppos;sp[zpos][sp[zpos].pz()-1]=z;sp[zpos].print();if(f){chty=2;callfunc(dap);}}
var dap=function(){$i("act").className=["p1","p2","p3","p4"][zpos];if(zpos===3)callfunc(dap_wj);else callfunc(dap_dn);}
var dac=function(){var s,l,i,j,c,f;s=sp[zpos];l=s.pz();for(i=0;i<l;i++)if(s[i].same(dapc))break;if(i>=l||dapc.samehuir()){callfunc(dap);return;}
for(;i<l-1;i++)s[i]=s[i+1];s[l-1]=new zhang(0,9);if(zpos!==3||autosort)s.sort();s.print();$i(["pc1","pc2","pc3","pc4"][zpos]).appendChild(dapc.divtag());expp(dapc);$i("dcp").value=ZH_DNXB[(zhuang.dong+3-zpos)%4];$i("dcz").className=dapc.divtag().className;if(!dapc.samehuir())
for(i=0;i<4;i++)if(i!=zpos){for(c=0,j=0,f=false;j<sp[i].pz()-1;j++)
if(sp[i][j].same(dapc))c++;else f=f||!sp[i][j].samehuir();if(c>=2&&f||c>=3){ppos=i;if(i===3)callfunc(pg_wj);else callfunc(pg_dn);return;}}
callfunc(zhuap);}
var clearpc=function(){var i;for(i=0;i<4;i++){var p=$i(["pc1","pc2","pc3","pc4"][i]);while(p.firstChild)
p.removeChild(p.firstChild);}}
var ginit=function(){var i;$i("gz").onclick=function(){if($i("act").className.indexOf("sd")!==-1)return;$i("act").className+=" sd";$i("hpzs").className="hz"+zhang.prototype.numhuir;$i("qihf").className="qf"+qihuf;$i("dpsdi").value=SDXZ[timeout_dn]/1000;}
for(i=1;i<=3;i++)
$i(["","hz1","hz2","hz3"][i]).onclick=function(){$i("hpzs").className=this.id;}
for(i=1;i<=3;i++)
$i(["","qf1","qf2","qf3"][i]).onclick=function(){$i("qihf").className=this.id;}
$i("sdqx").onclick=function(){var actn=$i("act"),s=actn.className;actn.className=s.substring(0,s.length-3);}
$i("sdck").onclick=function(){zhang.prototype.numhuir=$i("hpzs").className[2];qihuf=($i("qihf").className[2])*1;callfunc(minit);}}
window.onload=ainit;</script>
<body>
<!--[if lt IE 9]>
<span style="color: #FEA;">请更新到最新的IE浏览器（至少要求IE9），或换用最新的Chrome、Firefox等浏览器。</span>
<style>div{display:none;}</style>
<![endif]-->
<div id=main_body>
<div id=act>GNU GPL 3; 版本 0.1.2; 田生</div>
<div id=hxsp></div>
<header>
<div id=gz>
<button id=gzsd>规则设定</button>
</div>
<div id=sy_d>
剩余<input id=sy readonly tabindex=-1 />张
</div>
<div id=qszf_d>
第<input id=qs readonly tabindex=-1 />圈
<input id=zf readonly tabindex=-1 />家庄
</div>
<div id=hxs>
混儿<div id=hxsm>
</div>
</div>
</header>
<div id=su>
<div id=su1></div>
<div id=su2></div>
<div id=su3></div>
<div id=su4></div>
</div>
<div id=df>
<div id=fs1><input readonly id=zc1 tabindex=-1 /><input readonly id=scr1 tabindex=-1 /></div>
<div id=fs2><input readonly id=zc2 tabindex=-1 /><input readonly id=scr2 tabindex=-1 /></div>
<div id=fs3><input readonly id=zc3 tabindex=-1 /><input readonly id=scr3 tabindex=-1 /></div>
<div id=fs4><input readonly id=zc4 tabindex=-1 /><input readonly id=scr4 tabindex=-1 /></div>
</div>
<div id=xp>
<div id=xz>
<div id=xzm></div>
<button id=lp>自动理牌</button>
</div>
<div id=huangp>
荒牌
</div>
<div id=pc>
<div id=pc1></div>
<div id=pc2></div>
<div id=pc3></div>
<div id=pc4></div>
<div id=dcm><input id=dcp tabindex=-1 />家打出<div id=dcz class=z9></div></div>
</div>
</div>
<div id=hup>
<div id=hupj><input readonly id=hupwz tabindex=-1 /></div>
<div id=hup1></div>
<div id=hup2></div>
<div id=hupm><input readonly id=hupms tabindex=-1 /></div>
</div>
<div id=sd>
<div id=sdf></div>
<div id=sdm>
<div id=sdt>规则设定</div>
<div><span id=hpzs>混儿牌张数</span><button id=hz1>3张</button><button id=hz2>7张</button><button id=hz3>11张</button></div>
<div><span id=qihf></span><button id=qf1>有小和</button><button id=qf2>无小和</button><button id=qf3>无混儿吊</button></div>
<div id=sdb><button id=sdck>重开</button><button id=sdqx>取消</button></div>
</div>
</div>
</div>
</body>
</html>
